package testDemo.TCPTest;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerThread  implements Runnable{
    //新建服务器
    private Socket s;

    public ServerThread() throws IOException {
    }

    public ServerThread(Socket s) throws IOException {
        this.s = s;
    }

    @Override
    public void run() {
        try{
            while(true){
                //接收信息
                BufferedInputStream bis = new BufferedInputStream(s.getInputStream());
                //创建输出流
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Server"));
                //将信息存入文件夹Server
                byte[] byt = new byte[1024];
                int line;
                while((line=bis.read(byt))!=-1){
                    bos.write(byt,0,line);
                }
            }
//            //发送成功反馈
//            BufferedOutputStream Success = new BufferedOutputStream(s.getOutputStream());
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
